﻿using System.Collections.Generic;
using System.Reflection;

namespace MyBasicLib.Reflection
{
    internal sealed class MemberInfoComparer<T> : IEqualityComparer<T>, IComparer<T> where T : MemberInfo
    {
        private static readonly MemberInfoComparer<T> comparer = new MemberInfoComparer<T>();

        public static MemberInfoComparer<T> Default
        {
            get { return comparer; }
        }

        #region IComparer<T> Members

        public int Compare(T x, T y)
        {
            return x.MetadataToken - y.MetadataToken;
        }

        #endregion

        #region IEqualityComparer<T> Members

        public bool Equals(T x, T y)
        {
            return x == y;
        }

        public int GetHashCode(T obj)
        {
            return obj.MetadataToken;
        }

        #endregion
    }
}